package start.doubudouyin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import start.doubudouyin.entity.DateNum;
import start.doubudouyin.entity.UserActiveNum;
import start.doubudouyin.entity.Usersinfo;
import start.doubudouyin.entity.UserGenderNum;
import start.doubudouyin.mapper.FollowMapper;
import start.doubudouyin.service.UsersinfoService;
import start.doubudouyin.mapper.UsersinfoMapper;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @author 38798
* @description 针对表【usersinfo(用户信息表)】的数据库操作Service实现
* @createDate 2025-05-27 11:22:02
*/
@Service
public class UsersinfoServiceImpl extends ServiceImpl<UsersinfoMapper, Usersinfo>
    implements UsersinfoService{
    @Resource
    private UsersinfoMapper usersinfoMapper;
    @Autowired
    private FollowMapper followMapper;

    public String isPhoneExist(String phone) {
        if(usersinfoMapper.isPhoneExist(phone)!=null){
            return phone;
        }else{
            return null;
        }
    }

    public String isIdcardExist(String idcard){
        if(usersinfoMapper.isIdcardExist(idcard)!=null){
            return idcard;
        }else{
            return null;
        }
    }

    public String UserLogin(String phone,String password){
        return usersinfoMapper.UserLogin(phone,password);
    }
    public Integer isUserOnline(String userId){
        return usersinfoMapper.isUserOnline(userId);
    }

    public Integer updateonlineStatus(Integer onlineStatus,String userId){
        return usersinfoMapper.updateonlineStatus(onlineStatus,userId);
    }
    public Integer updatelastloginTime(Date lastloginTime, String userid){
        return usersinfoMapper.updatelastloginTime(lastloginTime,userid);
    }
    public Integer UserRegister(Usersinfo usersinfo){
        return usersinfoMapper.UserRegister(usersinfo);
    }

    //根据id查询用户信息
    public Usersinfo getUserById(String userId) {
        return usersinfoMapper.getUserById(userId);
    }
    public Integer UpdatePassword(String phone,String idcard,String password) {
        return usersinfoMapper.UpdatePassword(phone,idcard,password);
    }

    public String VerifyUser(String phone,String idcard){
        return usersinfoMapper.VerifyUser(phone,idcard);
    }

    public String VerifyPassword(String userId,String password){
        return usersinfoMapper.VerifyPassword(userId,password);
    }

    public String VerifyId(String userId,String idcard){
        return usersinfoMapper.VerifyId(userId,idcard);
    }
    public Integer UpdatePasswordById(String userId,String newPassword) {
        return usersinfoMapper.UpdatePasswordById(userId, newPassword);
    }

    public List<Usersinfo> findAll(){
        return usersinfoMapper.findAll();
    }

    public String VerifyPhone(String userId,String phone){
        return usersinfoMapper.VerifyPhone(userId,phone);
    }

    public Integer UpdatePhone(String userId,String phone){
        return usersinfoMapper.UpdatePhone(userId,phone);
    }

    @Override
    public DateNum getUserRange30() {
        List<Map<String, Object>> userRange30 = usersinfoMapper.getUserRange30();
        List<Object> date = userRange30.stream().map(dateMap -> dateMap.get("date")).toList();
        List<Object> num = userRange30.stream().map(numMap -> numMap.get("num")).toList();
        return new DateNum(date, num);
    }

    @Override
    public Boolean insertUsersPrefer(String userId) {
        if (usersinfoMapper.insertUsersPrefer(userId)>0)
            return true;
        return false;
    }

    @Override
    public List<Usersinfo> getFollowedInfo(String userId) {
        List<String> followedId = followMapper.getfollowedIdAndChat1(userId);
        if (followedId != null && followedId.size()>0){
            return usersinfoMapper.getFollowedInfo(followedId);
        }
        return null;
    }

    @Override
    public UserGenderNum getUserGenderNum() {
        UserGenderNum userGenderNum = new UserGenderNum();
        userGenderNum=usersinfoMapper.getGenderNum();
        return userGenderNum;
    }

    @Override
    public UserActiveNum getUserActiveNum() {
        UserActiveNum userActiveNum=new UserActiveNum();
        userActiveNum=usersinfoMapper.getUserActiveNum();
        return userActiveNum;
    }

    public Integer EditPersonal(String nickname,String signature,String userId){
        return usersinfoMapper.EditPersonal(nickname,signature,userId);
    }

    public Integer iconupload(String iconUrl,String userId){
        return usersinfoMapper.iconupload(iconUrl,userId);
    }
}




